<?php
/**
 *	FILENAME: 		/server_app/registration_status.php
 *	DESCRIPTION:	This script creates a valid JSON response that provides the user's registration status.
 *	AUTHOR:			Vincent Veltri 
 *	VERSION:		1.1.0
 *	LAST MODIFIED:	12/3/10
 **/

require_once($_SERVER['DOCUMENT_ROOT'] . "/config/environment.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/functions.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/logging.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/users.php");

enforceSSL();
setRequestParameters();

$userName = $_PARAMETERS["username"];

if (strlen($userName) == 0) {
    // Inproper Data
    $response["response_type"] = "error";
    $response["error_desc"] = "Username Not Provided.";
    logWarning("No user data supplied");
    echo(json_encode($response));
    die();
}

$userID = getUserIDValue($userName);

if ($userID !== FALSE) {
    $response["response_type"] = "success";
    $response["registered"] = "yes";
    $response["UID"] = $userID;
    logAction("User " . $userName . " already registered");
    echo(json_encode($response));
} else {
    $response["response_type"] = "success";
    $response["registered"] = "no";
    logAction("User " . $userName . " not yet registered");
    echo(json_encode($response));
}
